home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-03-15 | 4.6 KB | 207 lines | [TEXT/nX^n] |
-
- setMenuIcon MACRO &1,&2,&3 ; MenuHandle,Menu Item #,ICON Name.
-
- ; First, retrieve the attached ICON Resource:
-
- move.w RescIDBase,iconID
- addi.w #&2,iconID
- GetIcon iconID,=iconHdl
- move.l iconHdl,tempHdl ; Just temporary, folks !!
-
- ; Then, get the Resource file's Attributes so we can
- ; reset them later. After that, we make a copy of the
- ; ICON's Handle so that we can use the COPY for the MENU:
-
- HomeResFile iconHdl,=resFileRef
- GetResFileAttrs resFileRef,=resFileAttrs
- ; ----------
- move.l iconHdl,a0
- _HandToHand
- move.l a0,cyHdl
- ReleaseResource tempHdl ; The ORIGINAL Resource.
-
- ; Now, place the ICON's COPY in the Menu Item by
- ; changing the ICON's ID # to between 257 --> 511:
-
- move.w #&2,iconID
- addi.w #256,iconID
- AddResource cyHdl,#'ICON',iconID,!.name
- bra.s .1
- .name text #&&3
- align
-
- ; Reset to ORIGINAL Attributes to clear the resChanged
- ; Bit in the Attribute Byte so that we don’t update the
- ; Resource upon Closing AND so "Suitcase" DOES reset to
- ; the disk-based ID:
-
- .1 SetResFileAttrs resFileRef,resFileAttrs
- SetItmIcon &1,#&2,#&2 ; menuHandle,item #,icon #.
-
- ENDM
-
-
-
- move.l #6,d0 ; "jmp myMenuDefProc".
- _NewHandle,clear
- move.l a0,myMenuDefHdl
- bra.s .skipCode
- ; ----------
- .code jmp $CCCCCCCC ; 6 bytes.
- .absAddr dc.l myMenuDefProc-.absAddr
- ; ----------
- .skipCode move.l (a0),a0 ; Convert to a Pointer.
- lea .code,a1
- move.w (a1)+,(a0)+ ; Object Code word for "jmp".
- lea .absAddr,a1
- move.l (a1),d1
- lea (a1,d1.l),a1 ; Absolute address of
- move.l a1,(a0) ; "myMenuDefProc".
-
- …
- …
-
- NewMenu dCtlMenu,!newMenuName,=mainMenuHdl
- AppendMenu mainMenuHdl,!mainMenuItems
- InstallMenuProc mainMenuHdl
-
- …
- …
-
-
- InstallMenuProc MACRO &1 ; MenuHandle.
-
- move.l &1,a1 ; Handle -->
- move.l (a1),a1 ; Pointer.
- move.l myMenuDefHdl,menuDefHandle(a1) ; _NewHandle into Menu Record.
- ; ----------
- CalcMenuSize &1
-
- ENDM
-
-
-
- ; ======================================
- ; FUNCTION doChooseMessage (myMenu:MenuHandle; myRect:Rect; myPoint:Point;
- ; oldItem:INTEGER) : INTEGER;
- ;
- ; Returns Menu Item # you selected:
-
- doChooseMessage func integer
- .myMenu handle
- .myRect pointer
- .myPoint point
- .oldItem integer
- endParms
-
- locals
- .oldRect rect
- .itemKey char
- .itemMark char
- .itemRect rect
- endLocals
-
- .menuHdl requ a1 ; My worker bees ...
- .cyParamBlkPtr requ a2
- .cyDCEPtr requ a3
- .menuReg requ a4
- .theItem requ d3 ; Counts Items to get current one.
- .enableFlags requ d4 ; A disabled
- .shift requ d0 ; item ??
-
-
- enter
-
- movem.l d1-d7/a0-a4,-(sp) ; All your goodies.
- ; ==========
-
- move.l .myMenu,.menuHdl ; Handle -->
- move.l (.menuHdl),.menuReg ; Pointer.
- ;
- PtInRect .myPoint,.myRect,=d0
- beq .outsideMRect
-
- moveq #0,.theItem ; Initialize counter.
-
- .chooseLoop addq.w #1,.theItem
- push.l .myMenu
- push.l .myRect
- push.w .theItem
- pea .itemRect
- bsr GetItemRect
- ; ----------
- PtInRect .myPoint,!.itemRect,=d1
- beq.s .chooseLoop
-
- move.l menuID(.menuReg),d2 ; Support _MenuChoice
- move.w .theItem,d2 ; for the Mac II.
- move.l d2,MenuDisable
-
- .disabled? move.l menuEnable(.menuReg),.enableFlags
- BitAnd .enableFlags,#1,=d0 ; Bit #0 for ENTIRE Menu.
- beq.s .yup ; ... it's disabled.
- ; ----------
- moveq #1,.shift
- lsl.l .theItem,.shift
- BitAnd .enableFlags,.shift,=d1
- bne.s .deSelectOld
- ; ----------
- .yup moveq #0,.theItem ; Item is disabled.
-
- .deSelectOld cmp.w .oldItem,.theItem
- beq .aSelection
- tst.w .oldItem
- beq.s .selectNew ; The MenuBar, so don't invert back.
- ; ----------
- push.l .myMenu
- push.l .myRect
- push.w .oldItem
- pea .oldRect
- bsr GetItemRect
- InverRect !.oldRect ; Invert back to white, or de-select.
-
- .selectNew tst.w .theItem
- beq.s .itsDisabled
- ; ----------
- InverRect !.itemRect ; Blacken current selection.
-
- push.l .myMenu
- push.w .theItem
- pea .itemKey
- bsr GetItemKey
- cmpi.w #hMenuCmd,.itemKey
- bne.s .aSelection
- ;
- GetItmMark .myMenu,.theItem,!.itemMark
- GetMHandle .itemMark,=a0 ; = MenuHandle.
- clr.l -(sp)
- push.l a0
- push.l .myPoint
- bsr PopupSelect
- pop.l d1
- tst.w d1
- beq.s .onMenuBar ; Item's disabled.
- move.w #31,.theItem ; ... fake out Menu Manager so it
- ; doesn't blink a parent item.
- .itsDisabled
- .aSelection move.w .theItem,.result
- bra.s .end
- ; ==========
-
- .outsideMRect tst.w .oldItem
- beq.s .onMenuBar
- ; ----------
- push.l .myMenu
- push.l .myRect
- push.w .oldItem
- pea .oldRect
- bsr GetItemRect
- InverRect !.oldRect ; Back to white.
-
- .onMenuBar clr.w .result
-
- ; ==========
- .end movem.l (sp)+,d1-d7/a0-a4 ; Withdraw your life savings !!
-
- exit
-